package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.GmallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class GmallController {
    @Autowired
    GmallService gmallService;
    @RequestMapping("/binTotal")
    public JSONObject binTotal(String nowDate){
        List<Map> list = gmallService.binTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("name"));
            dataObject.put("value",map.get("price"));
            dataArray.add(dataObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }
    @RequestMapping("/zhuTotal")
    public JSONObject zhuTotal(String nowDate){
        List<Map> list = gmallService.zhuTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray catArray = new JSONArray();
        for (Map map : list) {
            catArray.add(map.get("name"));
        }
        dataObject.put("categories",catArray);
        JSONArray serArray = new JSONArray();
        JSONObject mapObject = new JSONObject();
        serArray.add(mapObject);
        mapObject.put("name","品牌名称");
        JSONArray mapArray = new JSONArray();
        mapObject.put("data",mapArray);
        for (Map map : list) {
            mapArray.add(map.get("price"));
        }
        dataObject.put("series",serArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
    @RequestMapping("/fanTotal")
    public JSONObject fanTotal(String nowDate){
        List<Map> list = gmallService.fanTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("price"));
        return jsonObject;
    }
    @RequestMapping("/lunTotal")
    public JSONObject lunTotal(String nowDate){
        List<Map> list = gmallService.lunTotal(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();
        dataObject.put("columns",colArray);

        JSONObject mapObject1 = new JSONObject();
        colArray.add(mapObject1);
        mapObject1.put("name","产品名称");
        mapObject1.put("id","subsys");

        JSONObject mapObject2 = new JSONObject();
        colArray.add(mapObject2);
        mapObject2.put("name","订单金额");
        mapObject2.put("id","module");

        JSONArray rowArray = new JSONArray();
        dataObject.put("rows",rowArray);
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("subsys",map.get("name"));
            mapObject.put("module",map.get("price"));
            rowArray.add(mapObject);
        }

        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
